package leetcode.jianzhioffer;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-01 10:35
 **/
public class JianZhiOffer18 {

    public ListNode deleteNode(ListNode head, int val) {
        //如果头结点的值等于val,直接返回下一个节点
        if (head.val == val) {
            return head.next;
        }
        ListNode temp = head;
        ListNode prev = new ListNode(0);
        prev.next = head;
        while (temp != null) {
            if (temp.val == val) {
                prev.next = temp.next;
                break;
            }
            prev = temp;
            temp = temp.next;

        }
        return head;
    }

}
